<template>
  <div class="city">
    <city-header></city-header>
    <city-search :allCities="allCities"></city-search>
    <city-list :hotCities="hotCities" :allCities="allCities" :curLoactionLetter="curLoactionLetter"></city-list>
    <city-alphabet :allCities="allCities" @letter-change="handlerletterChange"></city-alphabet>
  </div>
</template>
<script>
import CityHeader from "./components/Header";
import CitySearch from "./components/Search";
import CityList from "./components/List";
import CityAlphabet from "./components/Alphabet";
import axios from "axios";

export default {
  name: "City",
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data() {
    return {
      hotCities: [],
      allCities: {},
      curLoactionLetter: ""
    };
  },
  mounted() {
    this.getCityInfo();
  },
  methods: {
    getCityInfo() {
      axios.get("/apis/city.json").then(this.getCityInfoSucc);
    },
    getCityInfoSucc(res) {
      res = res.data;
      if (res.ret && res.data) {
        let data = res.data;
        this.hotCities = data.hotCities;
        this.allCities = data.cities;
      } else {
        console.log("error");
      }
    },
    handlerletterChange(letter) {
      this.curLoactionLetter = letter;
    }
  }
};
</script>
<style lang="stylus" scoped></style>